package com.scoy.honeymei.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.ViewGroup;

import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;

import com.scoy.honeymei.adapter.tabadapter.OyAdapter;
import com.scoy.honeymei.bean.PhoneBean;
import com.scoy.honeymei.databinding.ItemPhoneBinding;

import org.jetbrains.annotations.NotNull;

public class PhoneAdapter extends OyAdapter<PhoneBean> {


    public PhoneAdapter(Context context) {
        super(context);
    }

    @NonNull
    @NotNull
    @Override
    public RecyclerView.ViewHolder onCreateViewHolder(@NonNull @NotNull ViewGroup parent, int viewType) {
        ItemPhoneBinding binding = ItemPhoneBinding.inflate(LayoutInflater.from(parent.getContext()), parent, false);
        return new OyHolder(binding);
    }

    @Override
    public void onBindViewHolder(@NonNull @NotNull RecyclerView.ViewHolder holder, int position) {
        OyHolder mHolder = (OyHolder) holder;
        PhoneBean mBean = datalist.get(position);

        mHolder.binding.perNameTv.setText(mBean.getName());
        mHolder.binding.perPhoneTv.setText(mBean.getMobile());

        mHolder.itemView.setOnClickListener(v -> {
            if (onOneClick != null) {
                onOneClick.oneClick(position);
            }
        });

    }

    static class OyHolder extends RecyclerView.ViewHolder {
        private ItemPhoneBinding binding;

        public OyHolder(ItemPhoneBinding binding) {
            super(binding.getRoot());
            this.binding = binding;
        }
    }

}
